<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/3/13
 * Time: 15:32
 */
namespace  app\admin\controller;
use think\Db;
class Member extends Base {
    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $map = [];
            if(isset($user_gender)&&$user_gender != ""){
                $map['user_gender'] = $user_gender;
            }
            if(isset($user_type)&&$user_type != ""){
                $map['user_type'] = $user_type;
            }
            if(isset($key)&&$key!="")
            {
                $map['user_username|user_phone'] = ['like',"%" . $key . "%"];
            }
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            $count = Db::name('u_user')->where($map)->count();
            $list = Db::name('u_user')
                ->where($map)
                ->page($page,$limit)
                ->order('user_id desc')
                ->select ();
            return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$list]);
        }
        return $this->fetch();
    }

    /***
     * @return \think\response\Json
     * 冻结
     */
    public function forbidden(){
        $user_id = input('id');
        $res = Db::table('up_u_user')->where('user_id', $user_id)->setField('user_status', 3);
        if($res){
            return json(['code' => 200, 'msg' => "操作成功"]);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }

    /***
     * @return \think\response\Json
     * 解冻
     */
    public function enable(){
        $user_id = input('id');
        $res = Db::table('up_u_user')->where('user_id', $user_id)->setField('user_status', 1);
        if($res){
            return json(['code' => 200, 'msg' => "操作成功"]);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
}